<script type="text/javascript">
    LC.S.updateKey = function () {
        if (!checkForm($('.itemSet [name]'))) {
            return;
        }
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {id: LC.S.id, key: $('.itemSet [name=key]').val(), value: $('.itemSet [name=value]').val()},
            url: LC.S.serviceUrl + '/updateKey.do',
            success: function (rs) {
                if (rs.code == code.SUCCESS || rs.code == code.FINISH) {
                    LC.S.detail(LC.S.id);
                } else {
                    alert('code:' + rs.code + '\n' + msg[rs.code]);
                }
            }
        });
    }
    LC.S.removeKey = function (key) {
        if (!confirm('确定要删除该字典项吗？')) {
            return;
        }
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {id: LC.S.id, key: key},
            url: LC.S.serviceUrl + '/removeKey.do',
            success: function (rs) {
                if (rs.code == code.SUCCESS || rs.code == code.FINISH) {
                    LC.S.detail(LC.S.id);
                } else {
                    alert('code:' + rs.code + '\n' + msg[rs.code]);
                }
            }
        });
    }
    $(document).ready(function (e) {
        LC.S.id = '${dictionary._id}';
        LC.S.edit('.dictionaryDetail .edit', LC.S.serviceUrl + LC.S.URL_UPDATE, '${dictionary._id}');
        LC.initToolbarDetail();
    });
</script>
<div class="panel panel-default">
    <div class="panel-heading">字典详情</div>
    <div class="panel-body form-horizontal dictionaryDetail">
        <input type="hidden" name="dictionaryId" value="${dictionary._id}">

        <div class="form-group">
            <label class="col-sm-2 control-label">编 号：</label>
            <div class="col-sm-8"><p class="dictionaryId form-control-static">${dictionary._id}</p></div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">名 称：</label>
            <div class="col-sm-4">
                <p class="edit form-control-static" etype="text" regx="${check.title}"
                   name="title">${dictionary.title}</p>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">备注：</label>
            <div class="col-sm-5">
                <p class="edit form-control-static" etype="textarea" regx="${check.notes}"
                   name="notes">${dictionary.notes}</p>
            </div>
        </div>

        <div class="col-sm-8 col-sm-offset-1">
            <table class="table table-condensed table-hover">
                <caption>字典内容</caption>
                <thead>
                <tr>
                    <th>#</th>
                    <th>值</th>
                    <th>名称</th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                [#if dictionary.key??]
                    [#list dictionary.key?keys as key]
                    <tr>
                        <td class="col-sm-1">${key_index+1}</td>
                        <td class="col-sm-5">${key}</td>
                        <td class="col-sm-5">${dictionary.key[key]}</td>
                        <td class="col-sm-1">
                            <button class="btn btn-default" onclick="LC.S.removeKey('${key?js_string}')">删除</button>
                        </td>
                    </tr>
                    [/#list]
                [/#if]
                </tbody>
                <tfoot>
                <tr class="itemSet">
                    <td></td>
                    <td><input type="text" name="key" class="form-control" placeholder="值重复时覆盖"/></td>
                    <td><input type="text" name="value" class="form-control" placeholder="名称"/></td>
                    <td>
                        <button class="btn btn-default" onclick="LC.S.updateKey()">保存</button>
                    </td>
                </tr>
                </tfoot>
            </table>
        </div>
    </div>
</div>